# import class and constants
from ldap3 import Server, Connection, ALL

# define the server
s = Server('localhost:389', get_info=ALL)  # define an unsecure LDAP server, requesting info on DSE and schema

# define the connection
c = Connection(s, user='cn=admin,dc=xxxx,dc=yyy,dc=zzz', password='password')

# perform the Bind operation
if not c.bind():
    print('error in bind', c.result)
    raise Exception('failed to bind')
if not c.search('cn=auser,ou=ai,dc=xxx,dc=yyy,dc=zzz','(memberOf=cn=aGroup,ou=classes,dc=xxx,dc=yyy,dc=zzz)'):
    print('error in search:', c.result)
    raise Exception('failed to search')
print('authenticate successfully!')



